package com.css.fxfzdpzs.modules.hddc.controller;

import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.hddc.entity.first.DifferentConut;
import com.css.fxfzdpzs.modules.hddc.entity.first.FaultNum;
import com.css.fxfzdpzs.modules.hddc.entity.first.FaultTotal;
import com.css.fxfzdpzs.modules.hddc.entity.second.FaultNumLen;
import com.css.fxfzdpzs.modules.hddc.service.HddcService;
import com.css.fxfzdpzs.modules.hddc.vo.FaultNumVo;
import com.css.fxfzdpzs.modules.xczh.entity.first.DisasterVisitsCount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 全国活动断层分布图
 */
@Slf4j
@RestController
@RequestMapping("/hddc")
public class HddcController {
    @Autowired
    private HddcService hddcService;

    //地震活动断层探查管理系统访问次数   参数传 2
    @GetMapping("/getVisitNum")
    public RestResponse getVisitNum(@RequestParam String system) {
        RestResponse restResponse = null;
        try {
            Map<String, Object> map = hddcService.getVisitNum(system);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询地震活动断层探查管理系统访问次数失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省系统使用活跃度排名
    @GetMapping("/getProvinceRank")
    public RestResponse getProvinceRank(@RequestParam String system) {
        RestResponse restResponse = null;
        try {
            List<DisasterVisitsCount> list = hddcService.getProvinceRank(system);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省系统使用活跃度排名失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省(直辖市）断层数量情况统计
    @GetMapping("/getFaultNum")
    public RestResponse getFaultNum() {
        RestResponse restResponse = null;
        try {
            List<FaultNum> list = hddcService.getFaultNum();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省(直辖市）断层数量情况统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国断层总数
    @GetMapping("/getFaultTotal")
    public RestResponse getFaultTotal() {
        RestResponse restResponse = null;
        try {
            FaultNumVo total = hddcService.getFaultTotal();
            restResponse = RestResponse.succeed(total);
        } catch (Exception e) {
            String errormessage = "查询全国断层总数失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //活动时代数量及占比
    @GetMapping("/getDifferentConut")
    public RestResponse getDifferentConut() {
        RestResponse restResponse = null;
        try {
            List<DifferentConut> list = hddcService.getDifferentConut();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询活动时代数量及占比失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //***************二级********************
    //某个省地震活动断层探查管理系统访问次数
    @GetMapping("/getVisitNumByPro")
    public RestResponse getVisitNumByPro(@RequestParam String province) {
        RestResponse restResponse = null;
        try {
            DisasterVisitsCount count = hddcService.getVisitNumByPro(province);
            restResponse = RestResponse.succeed(count);
        } catch (Exception e) {
            String errormessage = "查询" + province + "地震活动断层探查管理系统访问次数失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //某个省(直辖市）活动断层段总数
    @GetMapping("/getFaultNumByPro")
    public RestResponse getFaultNumByPro(@RequestParam String province) {
        RestResponse restResponse = null;
        try {
            Integer num = hddcService.getFaultNumByPro(province);
            restResponse = RestResponse.succeed(num);
        } catch (Exception e) {
            String errormessage = "查询" + province + "省活动断层段总数失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //某省断层段数量情况统计
    @GetMapping("/getFaultNumLenByPro")
    public RestResponse getFaultNumLenByPro(@RequestParam String province) {
        RestResponse restResponse = null;
        try {
            List<FaultNumLen> faultNumLens = hddcService.getFaultNumLenByPro(province);
            restResponse = RestResponse.succeed(faultNumLens);
        } catch (Exception e) {
            String errormessage = "查询" + province + "省断层段数量情况统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //某个省活动时代数量及占比
    @GetMapping("/getDifferentConutByPro")
    public RestResponse getDifferentConutByPro(@RequestParam String province) {
        RestResponse restResponse = null;
        try {
            List<DifferentConut> list = hddcService.getDifferentConutByPro(province);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询" + province + "活动时代数量及占比失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //地图 返回断层数量（>300、150-300、50-150、0-50）对应的省列表
    @GetMapping("/getGeom")
    public RestResponse getGeom() {
        RestResponse restResponse = null;
        try {
            Map<String, List<FaultNumVo>> map = hddcService.getGeom();
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询断层段数量省列表失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
